<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>山东营销风云榜</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../css/part/tabHead.css">
    <link rel="stylesheet" href="../../../css/part/mini.css">
</head>

<body>

<div id="app">
    <div id="tableHead">
        <img src="../../../img/part/product/branchEvergreen.png" id="branchHead" align="center">
        <a href="../../portal/navigationYX.html"><img src="../../../img/portal/min.png" id="miniImg"></a>
        <table width="100%">
            <tr >
                <thead>
                <th width="6%">NO</th>
                <th width="14%">机构</th>
                <th width="16%">在册人力</th>
                <th width="16%">开单人力</th>
                <th width="18%">健康险开单人力</th>
                <th width="14%">开单人力占比</th>
                <th width="16%">保费占比</th>
                </thead>
            </tr>
        </table>
    </div>
    <div id="midDiv"></div>
    <div class="tableBody">
        <table id="tab" width="100%">
            <tbody id="tbody">
            </tbody>
        </table>
    </div>
</div>
</body>
<script src="../../../js/vue.js"></script>
<script src="../../../js/axios.js"></script>
<script src="../../../js/head.js"></script>
<script src="../../../js/jquery-3.2.1.min.js"></script>
<script src="../../../js/share.js"></script>

<script>
    window.onload = function () {
        new Vue({
            el: '#app',
            data() {
                return {
                    //中支名称
                    branchsName: '',

                    branchAllAgent: 0,
                    branchPreNum: 0,
                    branchEvergreenNum: 0,
                    preEvergreenYield: 0,
                    branchEvergreen: 0,
                    branchMonSure: 0,
                    branchEvergreenYield: 0,

                    pojo: {},
                    divHeight: 0,

                }
            },
            created() {
                this.getBranchEvergreen();
            },
            methods: {

                //获取各中支的数据
                getBranchEvergreen() {
                    document.getElementById("midDiv").style.height = window.getComputedStyle(document.getElementById("tableHead")).getPropertyValue("height");
                    setTimeout(() => {
                        axios.get(`/product/getBranchEvergreen`).then(response => {
                            this.pojo = response.data;
                            var str = "";//定义用于拼接的字符串
                            for (var i = 0; i < this.pojo.length; i++) {
                                this.branchAllAgent = this.branchAllAgent + this.pojo[i].branchAllAgent;
                                this.branchPreNum = this.branchPreNum + this.pojo[i].branchPreNum;
                                this.branchEvergreenNum = this.branchEvergreenNum + this.pojo[i].branchEvergreenNum;
                                this.branchEvergreen = this.branchEvergreen + this.pojo[i].branchEvergreen;
                                this.branchMonSure = this.branchMonSure + this.pojo[i].branchMonSure;
                                //拼接表格的行和列
                                str = "<tr><td width=\"6%\">" + (i + 1) + "</td>" +
                                    "<td width=\"14%\">" + this.pojo[i].branchsName + "</td>" +
                                    "<td width=\"16%\">" + this.pojo[i].branchAllAgent + "</td>" +
                                    "<td width=\"16%\">" + this.pojo[i].branchPreNum + "</td>" +
                                    "<td width=\"18%\">" + this.pojo[i].branchEvergreenNum + "</td>" +
                                    "<td width=\"14%\">" + this.dataHandle(this.pojo[i].preEvergreenYield) + "</td>" +
                                    "<td width=\"16%\">" + this.dataHandle(this.pojo[i].branchEvergreenYield) + "</td></tr>";
                                //追加到table中
                                $("#tbody").append(str);
                            }
                            str = "<tr><th colspan=\"2\" style=\"font-weight: bolder\">" + '合计:' + "</th>" +
                                "<th width=\"16%\">" + this.branchAllAgent + "</th>" +
                                "<th width=\"16%\">" + this.branchPreNum + "</th>" +
                                "<th width=\"18%\">" + this.branchEvergreenNum + "</th>" +
                                "<th width=\"14%\">" + this.dataHandle(this.doubleHandle(this.branchEvergreenNum, this.branchPreNum)) + "</th>" +
                                "<th width=\"16%\">" + this.dataHandle(this.doubleHandle(this.branchEvergreen, this.branchMonSure)) + "</th></tr>";
                            $("#tbody").append(str);

                        })
                    }, 200)
                },
                //数据处理
                dataHandle(_this) {
                    var data = _this + "";
                    if (data.indexOf(".") != -1) {
                        return data + '%'
                    }
                    if (data == -9999) {
                        return '-'
                    }
                    return data + ".0" + '%';
                },
                //处理两数相除
                doubleHandle(a, b) {
                    if (b == 0) {
                        return -9999;
                    } else {
                        return Math.round(a * 1000 / b) / 10;
                    }
                }

            }
        })
    }
</script>

</html>